<?php
/**
 * 用户信息类
 * @author liubin-bt
 * @property User_model $User_model
 */
class User extends Base{
    
    public function __construct(){
        parent::__construct();
        $this->load->model('User_model');
    }
    
    public function authInfo(){
        if( $_POST ){
            $data['real_name'] = $this->getSafeRequest('real_name', '');
            $data['job'] = $this->getSafeRequest('job', '');
            $data['institution'] = $this->getSafeRequest('institution', '');
            $data['email'] = $this->getSafeRequest('email', '');
            $data['city'] = $this->getSafeRequest('city', '');
            $data['description'] = $this->getSafeRequest('description', '');
            $data['invest_field'] = $this->getSafeRequest('invest_field', '');
            $data['invest_rotation'] = $this->getSafeRequest('invest_rotation', '');
            $data['invest_money'] = $this->getSafeRequest('invest_money', '');
            $data['files_card'] = $this->getSafeRequest('files_card', '');
            if( empty($data['real_name']) ){
                $this->outJsonData(0, '姓名不能为空');
            }
            if( empty($data['job']) ){
                $this->outJsonData(0, '职位不能为空');
            }
            if( empty($data['institution']) ){
                $this->outJsonData(0, '机构不能为空');
            }
            if( empty($data['email']) ){
                $this->outJsonData(0, '邮箱不能为空');
            }
            if( empty($data['city']) ){
                $this->outJsonData(0, '城市不能为空');
            }
            $exsit = $this->User_model->getAuthInfo($this->uid);
            if( $exsit ){
                $this->User_model->updateAuth(['uid'=>$this->uid], $data);
            } else {
                $data['uid'] = $this->uid;
                $res = $this->User_model->insertAuth($data);
            }
            $this->outJsonData(0, '添加成功');
        } else {
            $data = $this->User_model->getAuthInfo($this->uid);
            
            $this->outJsonData(0, $data);
        }
    }
}